package Sort;

import java.util.Arrays;

/**
 * 作者：吴超
 * 邮箱：wuchao_19931120@163.com
 * 时间：2022-01-18
 * 描述：
 */

public class BubbleSort {

    public static int[] bubbleSore(int[] numbers){
        int tmp = 0 ;
        int size = numbers.length;
        boolean flag = true;
        for (int i = 0; i < size - 1; i++) {
            for (int j = 0; j < size - 1 - i; j++) {
                if (numbers[j] > numbers[j+1]) {
                    flag = false;
                    tmp = numbers[j];
                    numbers[j] = numbers[j+1];
                    numbers[j+1] = tmp;
                }
                if (flag){
                    break;
                }
            }
        }
        return numbers;
    }

    public static void main(String[] args) {

        int[] numbes = {12, 4, 34, 1, 5, 7, 8, 6};
        System.out.println(Arrays.toString(bubbleSore(numbes)));

    }

}
